package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
	"hr-system/Global"
	"hr-system/RouterGroup"
	"log"
	"os"
)


func main() {
	InitConfig()
	Global.InitDB() // 连接postgresql
	// defer db.Close()

	r := gin.Default()
	r = routerGroup.CollectRoute(r) // 进入路由
	port := viper.GetString("server.port")
	log.Println(port+"	end")
	if port != "" {
		panic(r.Run(":" + port))
	}
	panic(r.Run())
}

func InitConfig() {

	workDir, _ := os.Getwd()
	viper.SetConfigName("application")
	viper.SetConfigType("yml")
	viper.AddConfigPath(workDir + "/config")
	err := viper.ReadInConfig()
	if err != nil { // 捕获读取中遇到的error
		panic(fmt.Errorf("Fatal error config file: %w \n", err))
	}
}
